import 'package:flutter/material.dart';
import '../../config/service_method.dart';
import '../../routers/application.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'dart:convert';
import '../../common/ok_toast.dart';
class ModifyPasswordProvider with ChangeNotifier{

   
    int _count = 0;
    int get count => _count;

    void increment() {
        _count++;
        notifyListeners();
    }


    void changePassword(BuildContext context,String oldPassword,String newPassword,String newPassword2)async{
        if(oldPassword == "" || newPassword == "" || newPassword2 == ""){
            OkToast.singleToast("请完善信息");
            return;
        }
        if(newPassword == newPassword2){
            var data = {
                "loginPwdB" :oldPassword , //原密码
                "repertPwd" :newPassword//新密码
            };
            await DioUtil.request(context,'/tqes/web/sysUser/repertPwd',formData: data).then((val){
                Map<String,dynamic> responseData = json.decode(val.toString());
                print(responseData);
                if(responseData["success"]){
                    OkToast.singleToast(responseData["msg"]);
                    Future<dynamic> future = Future(()async{
                        SharedPreferences prefs =await SharedPreferences.getInstance();
                        prefs.remove("loginToken");
                    });
                    future.then((val){
                        Application.router.navigateTo(context,"/login");
                    }).catchError((e){
                        print(e);
                    });
                }else{
                    OkToast.singleToast(responseData["msg"]);
                }

            });
        }else{
            OkToast.singleToast("输入的新密码不一致，请重新核对输入");
        }

    }

}